package com.example.mq.Controller;

import com.example.mq.Service.RocketMQProducer;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author mtl
 */
@RestController
@RequestMapping("/api")
public class MsgController {

    public static final String destination ="top-master";

    @Resource
    RocketMQTemplate rocketMQTemplate;
    @Resource
    RocketMQProducer rocketMQProducer;


    @RequestMapping("/buy")
    public void buy(){
        rocketMQTemplate.convertAndSend(destination,"普通发送convertAndSend");
    }


    @RequestMapping("/sendMsg1")
    public void sendMsg1(){
        Map<String, String> map = new HashMap<>();
        map.put("msg1","同步消息发送sendMsg1");
        map.put("msg2","第二条消息");
        rocketMQProducer.sendMsg(map);
    }

    @RequestMapping("/sendAsyncMsg2")
    public void sendAsyncMsg2(){
        rocketMQProducer.sendAsyncMsg("异步发送sendAsyncMsg");
    }

}
